package com.meng.webconfig;

import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.web.servlet.ErrorPage;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;


/**
 * 代码注册的Bean
 *
 * @author MENG
 * @version 2017/12/18
 * @see
 */
@Configuration
public class WebConfigurationBean
{

    /**
     *
     * Tomcat 错误页面代码配置
     *
     * @return
     */
    @Bean
    public EmbeddedServletContainerCustomizer containerCustomizer()
    {
        return new EmbeddedServletContainerCustomizer()
        {
            @Override
            public void customize(ConfigurableEmbeddedServletContainer container)
            {

                ErrorPage error401Page = new ErrorPage(HttpStatus.UNAUTHORIZED, "/err/401");

                ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/err/404");

                ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/err/500");

                container.addErrorPages(error401Page, error404Page, error500Page);
            }
        };
    }


}
